package br.com.opengti.webforum.ws.domain.impl;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Transient;

import br.com.opengti.webforum.ws.infra.dao.WebForumDomainSupport;

/**
 * @author Felipe Balbino <felipe@opengti.com.br>
 * @author Gabriel Cardelli <cardelli@opengti.com.br>
 */
@Entity
public class Usuario {
	
	@Transient private WebForumDomainSupport webForumDomainSupport;
	
	@Id
	@GeneratedValue
	private Integer id;
	
	private String nome;
	
	private String login;
	
	private String password;
	
	private String email;
	
	@OneToMany(mappedBy="usuario")
	private List<Topico> topicosCriados;
	
	@OneToMany(mappedBy="usuario")
	private List<Resposta> respostasEnviadas;
	
	@ManyToMany(mappedBy="seguidores")
	private List<Topico> topicosAssinados;
	
	@ManyToOne
	private Papel papel;
	
	/*
	 * 
	 * Business Method's
	 * 
	 */
	
	public void save(){
		webForumDomainSupport.getHibernateTemplate().save(this);
	}
	
	public void merge(){
		webForumDomainSupport.getHibernateTemplate().merge(this);
	}

}
